#pragma once

#include <vector>
#include <string>
#include "function.h"


struct PlotParams
{
	PlotParams() : r(0), g(0), b(0) {}
	PlotParams(float r, float g, float b) : r(r), g(g), b(b) {}

	//char line_type;
	float r;
	float g;
	float b;
};

class Plotter
{
private:
    Plotter();
    ~Plotter();

private:
	void initModel();

private:
	Plotter(Plotter const&);
	Plotter& operator=(Plotter const&);

public:
    static Plotter* instance();
	void drawFuction( Function * f, float a, float b, PlotParams const& params = PlotParams() );
	
public:
	void draw();
	void run();

private:
	void draw_axes();
    static void reshape ( int w, int h );
    static void output(float x, float y, std::string const& text, float scale = 1);
	static void screen2world(int x, int y, double * wx, double * wy);
	static void world2screen(int x, int y, double * wx, double * wy);
	static void mouse_move (int x, int y);
	static void mouse (int button, int state, int x, int y);
	static void mouse_wheel ( int wheel, int dir, int mouseX, int mouseY );
	static void arrow_keys ( int a_keys, int x, int y );
	static void keyboard ( unsigned char key, int, int );
	static void display ();

private:
	struct FunctionRec
	{
		FunctionRec(Function * f, float a, float b, PlotParams const& params)
			: f(f), start(a), end(b), params(params) {}

		Function * f; 
		float start;
		float end;
		PlotParams params;	
	};

	std :: vector <FunctionRec> functions; 
};

